import React, { Fragment } from 'react'
import { View, StyleSheet } from 'react-native'
import { connect } from 'react-redux'
import { ScaleS, ScaleT } from 'src/utils/ScreenUtil'
import { UPDATE_USERINFO_ACTION } from 'src/store/actions/userinfo'
import BaseManager from 'src/pageP/base/base-manager'
import EducationInfoCard from 'src/components/card-education-info'
import CustomButton from 'src/components/button/CustomButton'
import { CommonToast } from 'src/utils/ToastUtil'

// 发送行为
const mapDispatchToProps = dispatch => ({
  updateUserInfo (payload) {
    dispatch(UPDATE_USERINFO_ACTION(payload))
  }
})

@connect(({ CMineCenterStore }) => ({
  educations: CMineCenterStore.educations
}), mapDispatchToProps)
class CEducationInfo extends BaseManager {
  constructor (props) {
    super(props)
    this.titleText = '教育信息'
    this.completeText = '添加教育信息'
    this.showSaveBtn = false
  }

  childContentRender () {
    const { educations } = this.props
    return (
      <Fragment>
        {
          educations && educations.length > 0 && educations.map((item, index) => {
            return (
              <CustomButton onPress={this.educationItemClick} params={{ item }} key={item.id}>
                <EducationInfoCard style={styles.educationInfoItem} dataSource={item}/>
              </CustomButton>)
          })
        }
      </Fragment>
    )
  }

  onComplete () {
    const { educations, navigation } = this.props
    if (educations.length >= 3) {
      CommonToast('教育信息最多只能添加3条')
    } else {
      navigation.navigate('CEducationInfoManager')
    }
  }

  educationItemClick = ({ item }) => {
    const { educations } = this.props
    this.props.navigation.navigate('CEducationInfoManager', {
      education: item,
      showDelete: educations.length > 1
    })
  }
}

export default CEducationInfo

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  educationInfoItem: {
    marginLeft: ScaleS(20),
    marginTop: ScaleS(20)
  }
})
